<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>{:SEO('question-add','title')}</title>
<meta name="keywords" content="{:SEO('question-add','keywords')}">
<meta name="description" content="{:SEO('question-add','description')}">
<link href="__ROOT__/{:C('YTATA_TPL_DIR')}/public/css/question.css" rel="stylesheet" type="text/css">
<include file="public:header" />


<div class="qadd">


  <div class="addl">
  
  <if condition="$Think.session.ytata.uid eq ''">
  		<div class="logintip">
		  		<div class="txt font_yellow">&nbsp;&nbsp;&nbsp;&nbsp;已有账号？登陆后获取特权!</div>
		  <div class="txt">
				<div class="btn_green btn_inline_small btn_border J_user_login">立刻登录</div>
		  </div>
			  <div class="txt font_gray6">用第三方账号登录</div>
			  <div class="txt">
		  			<volist name="oauth_list" id="oauth">
			<a class="uu_api_login_btn {$key}" href="{:U('callback/index',array('mod'=>$key,'type'=>'login'))}"></a>
		</volist>
					<div class="clear"></div>
			  </div>
		  <div class="clear"></div>
		</div>
	</if>
	
	<form  name="add"  method="post" action="{:RU('question/addsave')}">
		
		<h2>清晰描述您的提问，可以获得更加准确的回答!</h2>
		
    <div class="inputbox zindextop">
		<input name="title" type="text" class="inputs w560"  placeholder="请在这里描述你的问题">
	  	<div class="categorysel J_cat_menu">选择问题分类</div>
		<input name="category1" id="J_category1" type="hidden" value="0">
		<input name="category2" id="J_category2" type="hidden" value="0">
		<div class="show_menu J_cat_show_menu">
		<ul>
		<ytata:cat listname="li" type="question" pid="0"/>
		<volist name="li.list" id="li">
		<li id="{$li.c_id}" title="{$li.c_title}"><span class="liimg"><img src="{$li.c_pic}" /></span>{$li.c_title}</li>
		</volist>
		</ul>
		</div>
	  </div>
		
		<h4>补充说明（选填）</h4>
	<div class="inputbox" >
		<textarea name="describe" cols="" rows="" class="inputs h100" placeholder="你可以继续在这里补充问题细节"></textarea>
		<div class="uploadbox">
			<div class="addimg" id="J_upload_btn" name="question_img">图片</div>
			<!--<input type="file" id="j_addmap_file" style="display: none;">-->
			<!--<div class="addmap" id="j_addmap">地点</div>-->
			<div class="clear"></div>
		</div>
	</div>  
	   <div class="tagdiv">
				      <div class="tagbox">
				        <div class="addtag" id="J_addtag">选择标签</div>
      					  <div class="tip">添加标签能获得快速准确的回答</div>
		              </div>
       </div>
	  <!--点击上传图片后图片出现在这里 最多上传3张,未上传下方DIV默认 display:none，非注册用户提问不允许上传图片 -->
	  
	        <div class="uploadimgbox">
		
			<div class="clear"></div>
	</div>
			
			<!--~~~~~~~~~~~~~~ -->
			
			<!--最多可选择3个标签 ,未添加下方DIV默认 display:none -->
     <div class="showtag">
				<div class="tip">你还可以添加<span>3</span>个标签</div>
				<div class="clear"></div>
    </div>


<!--如果可以获取到手机号 -->
	<if condition="($user.mobile  neq '') AND (C('YTATA_SMS_OPEN') eq '1')">
	         <div class="remind" >
					  <div class="td1">
							<div class="checkbox J_remind"><input name="sms_remind" type="hidden" value="0"></div>
					  </div>
					  <div class="td2">收到答案时短信通知我<span class="J_user_edit_mobile">{$user.mobile}[更改]</span></div>
					  <div class="td3">
					 <if condition="$Think.config.YTATA_GOLD_SEND_MB  gt 0 ">-{$Think.config.YTATA_GOLD_SEND_MB}</if>
					  </div>
					  <div class="clear"></div>
					  
			</div>
		</if>

<if condition="$Think.session.ytata.uid neq ''">
    <div class="reward">
			  <div class="td1">
			    <div class="checkbox J_reward_open"><input name="reward_open" type="hidden" value="0"></div>
			  </div>
			  <div class="td2">答题悬赏</div>
			  <div class="td3">
			    <div class="sel">
					  <div class="v J_reward_sel">-5</div>
					  <input name="reward" id="J_reward_input" type="hidden" value="5">
					  <div class="showreward J_reward_menu">
						  <ul>
						  <li title="-5" id="5">-5</li>
						  <li title="-10" id="10">-10</li>
						  <li title="-30" id="30">-30</li>
						  <li title="-50" id="50">-50</li>
						  <li title="-100" id="100">-100</li>
						  <li title="-200" id="200">-200</li>
						  </ul>
					  </div>
			    </div>
				
			  </div>
			  <div class="td4">你目前的财富值为 <strong id="J_user_gold">{$user.gold}</strong></div>
			  <div class="clear"></div>
    </div>     
	 
</if> 

<if condition="$Think.session.ytata.uid eq ''"> 

     <div class="mb">
	   <div class="mbmain"> 
	     <input type="text" class="mbiput" maxlength="11" onKeyUp="if(event.keyCode !=37 && event.keyCode != 39) value=value.replace(/\D/g,'');"onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/\D/g,''))"  placeholder="输入手机号"  name="mobile" >
	     
	     <input type="text" class="mbiput code" maxlength="11" onKeyUp="if(event.keyCode !=37 && event.keyCode != 39) value=value.replace(/\D/g,'');"onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/\D/g,''))" placeholder="输入验证码"  name="code">
		 <div class="mbiput btn J_send_code">获取验证码</div>
        </div>
	 </div>
	 
</if> 
	 
     <div class="btns">
	   <div class="td1">
	   <input name="" type="button" id="J_add" value="提交问题" class="btn"> 
	   </div>
	   
	   <if condition="$Think.session.ytata.uid neq ''">
	   
		   <div class="td2"><div class="checkbox J_anonymous_open"><input name="anonymous" type="hidden" value="0"></div></div>
		   <div class="td3">匿名提问</div>
		   <if condition="$Think.config.YTATA_GOLD_QUANTIFIER_ANONYMOUS  gt 0 "><div class="td4">-{$Think.config.YTATA_GOLD_QUANTIFIER_ANONYMOUS}</div></if>
	   
	   </if> 
	   
	   <div class="clear"></div>
    </div>
    </form>
	 
  </div>
  
  
  <!--右侧开始 -->
  
   <div class="addr">
   
   
     <div class="help">
	   <div class="tit">如何能获得快速准确的回答？</div>
	   <div class="td1">1</div>
	   <div class="td2">问题标题描述准确；</div>
	   <div class="clear"></div>
	    <div class="td1">2</div>
	   <div class="td2">选择正确发分类和标签；</div>
	   <div class="clear"></div>
	    <div class="td1">3</div>
	   <div class="td2">如果标题描述不清，可使用详细内容继续描述；</div>
	   <div class="clear"></div>
	    <div class="td1">4</div>
	   <div class="td2">适当的增加悬赏会吸引更多用户回答；</div>
	   <div class="clear"></div>
     </div>
	 
	 
	 
	 
	 
	 
   </div>
   
   
   <div class="clear"></div>
</div>
<include file="public:footer" />
<!--未登录发布问题 -->
<script type="text/javascript">
/********
/#####
/#####  验证表单和计算金币
/#####
*/
var send_val      =Number("{$Think.config.YTATA_GOLD_SEND_MB}");//收到答案时短信通知 所需积分
var anonymous_gold=Number("{$Think.config.YTATA_GOLD_QUANTIFIER_ANONYMOUS}");//匿名所需积分
var user_gold     =Number("{$user.gold|default="0"}");//会员目前拥有的积分，未登录为0
$(document).ready(function()
{
    $("#j_addmap").on('click', function () {
		$("#j_addmap_file").trigger('click');
    });
    $("#j_addmap_file").on('change', function(){
        console.log($(this).val());
        return false;
    });
        //提交问题  
        $("#J_add").click(function(){
			$(this).val('正在提交......').attr("disabled","disabled");
            title=$('input[name=title]').val();
			if (title==''){
				disapperTooltip("remind", "请填写问题标题");
				$(this).val('提交问题').removeAttr("disabled");
				 return false;
			}
			else if (title.length < 5) {
          		 disapperTooltip("remind", "您的提问标题过短，请将问题说明清楚！");
				 $(this).val('提交问题').removeAttr("disabled");
           		 return false;
        	}
			category1=$('input[name=category1]').val();
			if (category1=='' || category1=='0'){
				disapperTooltip("remind", "请选择问题分类！");
				$(this).val('提交问题').removeAttr("disabled");
				 return false;
			}
			<if condition="$Think.session.ytata.uid eq ''">
			code=$('input[name=code]').val();
			if (code==''){
				disapperTooltip("remind", "请填写短信验证码！");
				$(this).val('提交问题').removeAttr("disabled");
				 return false;
			}else{
					$.getJSON(ajaxURL, { act: "ajax_mobile_code_verify",code:code}, function(json){
						if (json.status==0){
							disapperTooltip("remind",json.content);
							$("#J_add").val('提交问题').removeAttr("disabled");
							return false;
						}else if (json.status==1){
							$("form[name=add]").submit();
						}else{
							disapperTooltip("remind","未知错误");
							$("#J_add").val('提交问题').removeAttr("disabled");
							return false;
						}
					});
			}
			<else />
			$("form[name=add]").submit();
			</if>
			
        });
		
		
		//发送验证码
		$('.J_send_code').live('click',function() {
					btn=$(this);
					if (btn.hasClass('btn_disabled')) return false;
					function settime(countdown) {
						if (countdown == 0) {
							btn.removeClass('btn_disabled');
							btn.text('获取验证码');
							countdown = {:C('YTATA_SMS_SETTIME')};
							return;
						} else {
							btn.addClass('btn_disabled');
							btn.text('重新发送' + countdown + '秒');
							countdown--;
						}
						setTimeout(function() {
							settime(countdown)
						},1000)
					}
					var mobile=$('input[name=mobile]').val();
					if (mobile.length==''){
						disapperTooltip("remind",'请填写手机号');
						return false;
					}
					if (mobile.length!=11){
						disapperTooltip("remind",'请填写正确的手机号');
						return false;
					}
					btn.addClass('btn_disabled').html('正在发送中.');
					$.getJSON(ajaxURL, { act:"ajax_send_mobile_code",mobile:mobile,in_user:0}, function(json){
						if (json.status==0){
							btn.removeClass('btn_disabled').html('获取验证码');
							disapperTooltip("remind",json.content);
						}else if (json.status==1){
							disapperTooltip("success",json.content);
							settime({:C('YTATA_SMS_SETTIME')});
						}else{
							btn.removeClass('btn_disabled').html('获取验证码');
							disapperTooltip("remind",json.content);
						}
					});
		});
		//开启收到答案时短信通知项
		$('.J_remind').click(function()
		{
			checkedinput=$(this).find("input");
			v=checkedinput.val();
			if (v=='0'){
				if (user_gold<send_val){
				disapperTooltip("remind","你的{:C('YTATA_GOLD_BYNAME')}不够用了，平时多攒点呀～");
				return false;
				}
				checkedinput.val(1);
				$(this).addClass('select');
				user_gold=user_gold-send_val;
				$("#J_user_gold").text(user_gold);
			}else{
				checkedinput.val(0);
				$(this).removeClass('select');
				user_gold=user_gold+send_val;
				$("#J_user_gold").text(user_gold);
			}
		});
		//
		//开启答题悬赏
		$('.J_reward_open').click(function()
		{
			reward_val=Number($('input[name=reward]').val());
			checkedinput=$(this).find("input");
			v=checkedinput.val();
			if (v=='0'){
				if (user_gold<reward_val){
				disapperTooltip("remind","你的{:C('YTATA_GOLD_BYNAME')}不够用了，平时多攒点呀～");
				return false;
				}
				checkedinput.val(1);
				$(this).addClass('select');
				user_gold=user_gold-reward_val;
				$("#J_user_gold").text(user_gold);				
			}else{
				checkedinput.val(0);
				$(this).removeClass('select');
				user_gold=user_gold+reward_val;
				$("#J_user_gold").text(user_gold);	
			}
		});
		//开启匿名
		$('.J_anonymous_open').click(function()
		{
			checkedinput=$(this).find("input");
			v=checkedinput.val();
			if (v=='0'){
				if (user_gold<anonymous_gold){
				disapperTooltip("remind","你的{:C('YTATA_GOLD_BYNAME')}不够用了，平时多攒点呀～");
				return false;
				}
				checkedinput.val(1);
				$(this).addClass('select');
				user_gold=user_gold-anonymous_gold;
				$("#J_user_gold").text(user_gold);				
			}else{
				checkedinput.val(0);
				$(this).removeClass('select');
				user_gold=user_gold+anonymous_gold;
				$("#J_user_gold").text(user_gold);	
			}
		});
	
});
</script>
<script type="text/javascript">
	var uploadUrl = "{:RU('Upload/img')}";
</script>
<script src="__ROOT__/{:C('YTATA_TPL_DIR')}/public/js/ajaxfileupload.js"></script>
<script src="__ROOT__/{:C('YTATA_TPL_DIR')}/public/js/fileupload.js"></script>
<script type="text/javascript">
/********
/#####
/#####  图片相关
/#####
*/
$(document).ready(function()
{
var IMGindex=1;
var IMGnum=3;//允许上传数量
var TAGnum=3;//允许TAG添加数量
// 上传图标
$.upload('#J_upload_btn',{type:'question_img'},function(result){
		if(result.status == 1){;
			html=htmlSTR(IMGindex);
			if ($(".uploadimgbox .imgbox").length>=IMGnum){
				disapperTooltip("remind","最多只能上传"+IMGnum+"张图片");
				return false;
			}
			var imgobj=".uploadimgbox .imgs"+(Number(IMGindex)-1);
			$(".uploadimgbox").prepend(html).show();
			$(imgobj).find('a').attr('href',result.content.src);
			$(imgobj).find('img').attr('src',result.content.src);
			$(imgobj).find('input').val(result.content.id);
		} else {
			disapperTooltip("remind", "上传失败："+result.content);
		}
		//生成html
		function htmlSTR(index){
			html="";
			html+="<div class=\"imgbox imgs"+index+"\">";
			html+="<a href=\"#\" target=\"_blank\"><input name=\"img[]\" type=\"hidden\" value=\"#\"><img src=\"#\" border=\"0\" /></a>";
			html+="<div class=\"del J_img_del\">删除</div>";
			html+="</div>";
			IMGindex=index+1;
			return html;
		}
	});
	//删除上传图片
	$('.J_img_del').live('click',function() {
	 	$(this).parent(".imgbox").remove();
		if ($(".uploadimgbox .imgbox").length==0) $(".uploadimgbox").hide();
	});
	//修改手机
		$('.J_user_edit_mobile').live('click',function() {
		 var YTATADialog = $(this).dialog({
		        title: false,
        		loading: true,
				footer: false,
				header: false,
				border: false,
				backdrop: false
		});
		 $.getJSON(ajaxURL, { act: "ajax_edit_mobile"}, function(json){
					if (json.status==0){
						YTATADialog.hide();
						disapperTooltip("remind", json.content);
					}else if (json.status==1){
						YTATADialog.hide();
						var MDialog = $(this).dialog({
								title: "修改手机号",
								content:json.content,
								footer: true,
								header: true,
								border: true,
								innerPadding: true,
								backdrop: true,
						 		yes: function() {
									
									mobile=$("input[name='mobile']").val();
									code=$("input[name='code']").val();
								$.getJSON(ajaxURL, { act: "ajax_edit_mobile",mobile:mobile,code:code,edit:"1"}, function(json){
										if (json.status==0){
											disapperTooltip("remind", json.content);
										}else if (json.status==1){
 											disapperTooltip("success",json.content);
											$('.J_user_edit_mobile').text(json.mobile+'[修改]');
											$('.modal').remove();
											$('.modal_backdrop').remove();
										}else{
											disapperTooltip("remind","修改失败，未知错误");
										}
								});	
							}
						});
						MDialog.setCloseDialog(false);
					}else{
						YTATADialog.hide();
						disapperTooltip("remind","未知错误");
					}
		});
	});
	
	

});
</script>
<script type="text/javascript">
$(document).ready(function()
{
/********
/#####
/#####  下拉，分类和悬赏选择
/#####
*/

//一二级分类切换
	<if condition="C('YTATA_CAT_LEVEL_QUESTION') eq '1'">
	ShowMenu('.J_cat_menu','#J_category1','.J_cat_menu','.J_cat_show_menu');
	<else />
	//二级分类
	$('.J_cat_menu').live('click',function() {
		 var YTATADialog = $(this).dialog({
		        title: false,
        		loading: true,
				footer: false,
				header: false,
				border: false,
				backdrop: false
		});
		 $.getJSON(ajaxURL, { act: "ajax_cat_list",type:1}, function(json){
					if (json.status==0){
						YTATADialog.hide();
						disapperTooltip("remind", json.content);
					}else if (json.status==1){
						YTATADialog.hide();
						var MDialog = $(this).dialog({
								title: "请选择分类",
								content:json.content,
								footer: true,
								header: true,
								border: true,
								innerPadding: true,
								backdrop: true,
						 		yes: function() {
									cbtn=$(".ajax_cat_list span.select");
									ctit=cbtn.attr('title');
									category1=cbtn.attr('category1');
									category2=cbtn.attr('category2');
									if (ctit!='')
									{
										$('.J_cat_menu').text(ctit);
										$('#J_category1').val(category1);
										$('#J_category2').val(category2);
										$('.modal').remove();
										$('.modal_backdrop').remove();
									}
								 
							}
						});
						MDialog.setCloseDialog(false);
					}else{
						YTATADialog.hide();
						disapperTooltip("remind","未知错误");
					}
		});
	});
	
	</if>
	//悬赏金币选择
	ShowMenu('.J_reward_sel','#J_reward_input','.J_reward_sel','.J_reward_menu');
});
</script>
<script type="text/javascript">
$(document).ready(function()
{
/********
/#####
/#####  TAG相关
/#####
*/
//打开添加标签页JS操作 (ajax_tag_list.html页面操作)
TAGnum=3;//允许TAG添加数量

//打开标签弹窗
$('#J_addtag').live('click',function() {
		 var YTATADialog = $(this).dialog({
		        title: false,
        		loading: true,
				footer: false,
				header: false,
				border: false,
				backdrop: false
		});
		
		tags=$(".showtag .tag");
		tags_str='';
		if (tags.length>0)
		{
			tags_arr=new Array();
			tags.each(function(i){
			tags_arr[i]=$(this).attr('title');
			});
			tags_str=tags_arr.join("__yangtata__");
		}
		 $.getJSON(ajaxURL, { act: "ajax_tag_list",tags:tags_str}, function(json){
					if (json.status==0){
						YTATADialog.hide();
						disapperTooltip("remind", json.content);
					}else if (json.status==1){
						YTATADialog.hide();
						var MDialog = $(this).dialog({
								title: "请选择标签",
								content:json.content,
								footer: true,
								header: true,
								border: true,
								innerPadding: true,
								backdrop: true,
						 		yes: function() {
									tags=$(".ajax_tag_list .tagli.select");
									if (tags.length>0)
									{
										html='';
										tags.each(function(i){
										html+='<div class="tag" title="'+$(this).attr('title')+'">'+$(this).attr('title')+'<input name="tag[]" type="hidden" value="'+$(this).attr('title')+'"></div>';
										});
										$('.showtag .tag').remove();
										$('.showtag').prepend(html).show();
										unm=TAGnum-tags.length;
										$('.showtag .tip span').html(unm);
									}
								 
							}
						});
					}else{
						YTATADialog.hide();
						disapperTooltip("remind","未知错误");
					}
		});
	});
//从窗口选择标签
$('.ajax_tag_list .tagli').live('click',function()
{
	if ($(this).hasClass('select')){
	$(this).removeClass('select');
	}else{
	$(this).addClass('select');
	}
	if ($(".ajax_tag_list .tagli.select").length>TAGnum){
	disapperTooltip("remind","最多只能选择"+TAGnum+"个标签");
	$(this).removeClass('select');
	}
});
//搜索标签
$('.J_sotag_btn').live('click',function()
{
	btn=$(this);
	btn.attr("disabled","disabled").addClass('btn_disabled');
	tagkey=$('#J_tagkey').val();
	if (tagkey.length==0)
	{
		disapperTooltip("remind","请填写关键字！");
		btn.removeAttr("disabled").removeClass('btn_disabled');
		return false;
	}
	$.getJSON(ajaxURL,{act: "ajax_tag_so",tagkey:tagkey}, function(json){
					
					if (json.status==0)
					{
						disapperTooltip("remind", json.content);
						btn.removeAttr("disabled").removeClass('btn_disabled');
					}
					else if (json.status==1)
					{
							if (json.count==0)
							{
								$('.ajax_tag_list .soshow').hide();
								$('.ajax_tag_list .soempty').show();
								$(".ajax_tag_list .soempty strong").html(json.key);
								$(".ajax_tag_list .soempty .J_add_tag_key").attr('title',json.key);
							}
							else
							{
								$('.ajax_tag_list .soshow').show();
								$('.ajax_tag_list .soempty').hide();
								tag=json.content;
								htm='';
								for(var i in tag)
								{
								htm+="<div class=\"tagli\" title=\""+tag[i].tag+"\">"+tag[i].tag+"</div>";
								}
								htm+="<div class=\"clear\"></div>";
								$(".ajax_tag_list .soshow .stxt").html(htm);
							}
							btn.removeAttr("disabled").removeClass('btn_disabled');
					}else{
						disapperTooltip("remind","未知错误");
						//
						btn.removeAttr("disabled").removeClass('btn_disabled');
						//
					}
	});

});
//从搜索结果添加标签
$('.J_add_tag_key').live('click',function()
{
	tag=$(this).attr('title');
	if ($(".ajax_tag_list .tagli[title='"+tag+"']").length>0)
	{
	disapperTooltip("remind",tag+"已存在，不能重复添加标签");
	return false;
	}
	else
	{
		if ($(".ajax_tag_list .tagli.select").length>=TAGnum){
		html="<div class=\"tagli\" title="+tag+">"+tag+"</div>";
		$(".ajax_tag_list .tlist .clear").before(html);
		}
		else
		{
		html="<div class=\"tagli select\" title="+tag+">"+tag+"</div>";
		$(".ajax_tag_list .tlist .clear").before(html);
		}		
	}
});
//删除所选标签
$('.showtag .tag').live('click',function()
{
	$(this).remove();
	tags=$('.showtag .tag');
	if (tags.length==0)
	{
	$('.showtag').hide();
	}
	unm=TAGnum-tags.length;
	$('.showtag .tip span').html(unm);
});
	
});
</script>
</body>
</html>
